export BUILD_TOPDIR=$(PWD)
export STAGING_DIR=$(BUILD_TOPDIR)/tmp
export TOPDIR=$(PWD)
export UBOOTDIR=$(TOPDIR)/u-boot

######## Toolchain config ########
CONFIG_TOOLCHAIN_PREFIX=/root/openwrt-sdk-ar71xx-gcc-4.8/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-
##################################

export CROSS_COMPILE=$(CONFIG_TOOLCHAIN_PREFIX)
export MAKECMD=make ARCH=mips

export UBOOT_GCC_4_3_3_EXTRA_CFLAGS=-fPIC
export COMPRESSED_UBOOT=0

ifeq ($(BOARD_TYPE),e8820)
export UBOOT_CONFIG_TARGET=board956x
export CFG_BOARD_NAME=zte e8820 v1
export AH_CAL_IN_FLASH_PCI=1
export AR7240_EMU=1
export ATH_CFG_SGMII=1
export ATH_CONFIG_SWAP_SGMII=0
export ATH_GMAC0_MII=ATHR_SGMII
export ATH_GMAC1_MII=ATHR_SGMII
export ATH_GMAC_GE0_IS_CONNECTED=1
export ATH_S17_MAC0_SGMII=1
export ATH_SGMII_FORCED=1
export BIG_ENDIAN_HOST=1
export BUILD_CONFIG=_vlan
export BUILD_TYPE=jffs2
export BUS=dual
export CFG_BOARD_TYPE=ap152
export ddr_cas=5
export ETH_CONFIG=_s17
export FLASH_SIZE=16
export pll=CFG_PLL_775_650_258
endif

ifeq ($(BOARD_TYPE),e8821)
export UBOOT_CONFIG_TARGET=board956x
export CFG_BOARD_NAME=zte e8821
export AH_CAL_IN_FLASH_PCI=1
export AR7240_EMU=1
export ATH_CFG_SGMII=1
export ATH_CONFIG_SWAP_SGMII=0
export ATH_GMAC0_MII=ATHR_SGMII
export ATH_GMAC1_MII=ATHR_SGMII
export ATH_GMAC_GE0_IS_CONNECTED=1
export ATH_S17_MAC0_SGMII=1
export ATH_SGMII_FORCED=1
export BIG_ENDIAN_HOST=1
export BUILD_CONFIG=_vlan
export BUILD_TYPE=jffs2
export BUS=dual
export CFG_BOARD_TYPE=ap152
export ddr_cas=5
export ETH_CONFIG=_s17
export FLASH_SIZE=1
export ATH_DUAL_FLASH=1
export ATH_SPI_NAND=1
export ATH_SPI_NAND_CS_GPIO=6
export pll=CFG_PLL_775_650_258
endif

TARGETS=e8820 e8821

IMAGEPATH=$(BUILD_TOPDIR)/bin
UBOOT_BINARY=u-boot.bin
UBOOTFILE=$(BOARD_TYPE)_u-boot.bin

all:
ifeq (,$(filter $(BOARD_TYPE), $(TARGETS)))
	@echo "Run 'make BOARD_TYPE=<target_name>'"
	@echo "Available targets: $(TARGETS)"
else
	cd $(UBOOTDIR) && $(MAKECMD) $(UBOOT_CONFIG_TARGET)_config
	cd $(UBOOTDIR) && $(MAKECMD) all
	@echo Copy binaries to $(IMAGEPATH)/$(UBOOTFILE)
	mkdir -p $(IMAGEPATH)
	cp -f $(UBOOTDIR)/$(UBOOT_BINARY) $(IMAGEPATH)/$(UBOOTFILE)
	@make clean
	@echo Done
endif
	
clean:
	cd $(UBOOTDIR) && $(MAKECMD) distclean
